using System;
using System.Web.Security;
using Microsoft.SharePoint.WebControls;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.Utilities;
using IWCommunity.Common;

namespace IWCommunity.UserRoleManagement
{
    /// <summary>
    /// Code behind for RolesNew.aspx
    /// </summary>
    public class RoleNew : LayoutsPageBase
    {
        protected InputFormTextBox txtRole;
        protected Label lblMessage;

        protected void OnSubmit(object sender, EventArgs e)
        {
            // add the role to the membership provider
            if (!Roles.RoleExists(txtRole.Text))
            {
                try
                {
                    Roles.CreateRole(txtRole.Text);
                    // redirect to roles list
                    Response.Redirect("RolesDisp.aspx");
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex, true);
                }
            }
            else
            {
                lblMessage.Text = "User Already Exists";

            }
        }
    }
}
